;;; memo-mode.el --- Major mode for editing Memo scripts -*- lexical-binding: t; -*-
;;; Commentary:
;; This package provides a major mode for editing Memo scripts used in
;; Cadence EDA tools.
;;; Code:

(defgroup memo-mode nil
  "Major mode for editing Memo scripts."
  :group 'languages)

(defcustom memo-indent-level 4
  "Number of spaces for each indentation step in `memo-mode'."
  :type 'integer
  :group 'memo-mode
  :safe 'integerp)

(defface key1-face
  '((t :foreground "#c1252d"
       :background "#d6d823"))
  nil)

(defface key2-face
  '((t :foreground "#aa8000"))
  nil)

(defface key3-face
  '((t :foreground "#12c2d2"))
  nil)

(defface key4-face
  '((t :foreground "#d7dce3"
       :background "#bc42de"))
  nil)

(defface block-comment-face
  '((t :foreground "#b7659c"
       :background "#f1ecee"))
  nil)

(defface comment-face
  '((t :foreground "#e13e3f"))
  nil)

(defface string-face
  '((t :foreground "#1cb01c"))
  nil)

(defface number-face
  '((t :foreground "#f971bb"))
  nil)

(defvar memo-key1
  '("NA" "NO" "No" "Note" "attention" "false" "imp" "important" "later" "note" "notice" "og" "ongoing" "参考点" "已总结" "未总结" "注" "注意" "详见专题"))

(defvar memo-key2
  '("Figure" "abort" "cancelledtodo" "cxtodo" "discussed" "done" "donetodo" "duplicated" "figure" "formula" "movedtodo" "no" "nomoretodo" "noneed" "notnow" "open" "pause" "pic" "公式" "图"))

(defvar memo-key3
  '("..." ">>>" "?" "digest" "failedtodo" "nouse" "ogtodo" "ongoingtodo" "torephrase" "torfz"))

(defvar memo-key4
  '("delayed_todo" "detodo" "todo" "TODO"))

(defvar memo-font-lock-keywords
  `(
    (,(regexp-opt memo-key1 'symbols) . key1-face)
    (,(regexp-opt memo-key2 'symbols) . key2-face)
    (,(regexp-opt memo-key3 'symbols) . key3-face)
    (,(regexp-opt memo-key4 'symbols) . key4-face)

    ;; Variables (starting with ?)
    ; ("\\<?\\sw+" . font-lock-variable-name-face)
    ("#.*" . comment-face)

    ;; Number
    ("[0-9]+" . number-face)

    ;; Strings
    ("\".*\"" . string-face)
    )
  "Highlighting expressions for Memo mode.")

;;;###autoload
(define-derived-mode memo-mode prog-mode "Memo"
  "Major mode for editing Memo scripts."
  ;; (setq-local font-lock-defaults '(memo-font-lock-keywords))
  ;; (setq-local parse-sexp-ignore-comments t)
  (setq-local indent-tabs-mode nil)
  (setq-local tab-width memo-indent-level)

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.memo\\'" . memo-mode))

(provide 'memo-mode)
;;; memo-mode.el ends here
